﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using MidimediaFinder.Resources;

namespace MidimediaFinder
{
    public partial class PromotionPage : PhoneApplicationPage
    {
        public static promotion SelectedItem;
        // Constructor
        public PromotionPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(ItemPage_Loaded);
        }

        // Load data for the ViewModel Items
        private void ItemPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
            if (SelectedItem == null)
            {
                NavigationService.GoBack();
            }
            
            SetElements();
        }

        private void SetElements()
        {
            if (SelectedItem.Hint != "")
            {
                HintArea.Text = SelectedItem.Hint;
            }
            else
            {
                HintArea.Visibility = System.Windows.Visibility.Collapsed;
                HintLabel.Visibility = System.Windows.Visibility.Collapsed;
            }

            StartTimeArea.Text = SelectedItem.StartTime;
            StartDateArea.Text = SelectedItem.StartDate;
            EndTimeArea.Text = SelectedItem.EndTime;
            EndDateArea.Text = SelectedItem.EndDate;
            Short_DescArea.Text = SelectedItem.Short_description;

            if (SelectedItem.Promotion_Description != "")
            {
                DescriptionArea.Text = SelectedItem.Promotion_Description;
            }
            else
            {
                DescriptionArea.Visibility = System.Windows.Visibility.Collapsed;
                DescriptionLabel.Visibility = System.Windows.Visibility.Collapsed;
            }

            if (SelectedItem.Bonus=="1")
            {
                BonusArea.Text = SelectedItem.Bonus_desc;
            }
            else
            {
                PivotControl.Items.Remove(Pivot_Bonus);
            }
        }
        

        private void PromoterButton_Click(object sender, RoutedEventArgs e)
        {
            ItemPage.SelectedItem = SelectedItem;
            NavigationService.Navigate(new Uri("/ItemPage.xaml?show_comments=0", UriKind.Relative));
        }

        private void ShareEMailButton_Click(object sender, RoutedEventArgs e)
        {
            EmailComposeTask etc = new EmailComposeTask();
            etc.Body = Storage.ComposePromotionEmail(SelectedItem);
            etc.Subject = Strings.Title + Strings.Promotion;
            etc.Show();
        }

        private void ShareSMsButton_Click(object sender, RoutedEventArgs e)
        {
            SmsComposeTask etc = new SmsComposeTask();
            etc.Body = Storage.ComposePromotionSMS(SelectedItem);
            etc.Show();
        }
    }
}